﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BIS.Portal.Modules.CMS.Entity;
using BIS.Utility.DAL;
using BIS.Utility.DAL.DataMapper;

namespace BIS.Portal.Modules.CMS.DAL
{
    public class ClientCmsArticleCategoryAndCategoryDAL
    {
        /// <summary>
        /// Gets Category name from Category and Category language
        /// </summary>
        /// <param name="iParent_category_id"></param>
        /// <param name="iLanguage_in_use_id"></param>
        /// <returns></returns>
        public static IList<ClientCmsArticleCategoryAndCategoryEntity> GetCategoryAndLanguage(int iParent_category_id, int iLanguage_in_use_id)
        {
            IList<ClientCmsArticleCategoryAndCategoryEntity> list;
            SqlParameter[] _param = new SqlParameter[] { new SqlParameter("@parent_category_id", iParent_category_id), new SqlParameter("@language_in_use_id", iLanguage_in_use_id) };
            using (IDataReader reader = SqlHelper.ExecuteReader(DALConnection.ConnectionString,
                                        CommandType.StoredProcedure,
                                        "BIS_sCMS_ARTICLE_CATEGORY_DISPLAY_SelectCateName", _param))
            {
                list = EntityMapper.FillCollection<ClientCmsArticleCategoryAndCategoryEntity>(reader);
            }

            return list;
        }
        /// <summary>
        /// Lấy category name theo category id
        /// </summary>
        /// <param name="iCategoryId"></param>
        /// <returns></returns>
        public  static ClientCmsArticleCategoryAndCategoryEntity GetCategoryNameById(int iCategoryId)
        {
            ClientCmsArticleCategoryAndCategoryEntity objCate = null;
            using (IDataReader reader = SqlHelper.ExecuteReader(DALConnection.ConnectionString,
                                        CommandType.StoredProcedure,
                                        "BIS_sCMS_ARTICLE_CATEGORY_DISPLAY_SelectCateById", new SqlParameter("@category_id", iCategoryId)))
            {
                objCate = EntityMapper.FillObject<ClientCmsArticleCategoryAndCategoryEntity>(reader);
            }

            return objCate;
            
        }
        

    }
}
